<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>银币卡</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/style/admin.css" media="all">
<body layadmin-themealias="default" style="">
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item" style="height: 20px;line-height: 20px;">
                <div class="layui-inline" style="margin-right: 0px;">
                     <span class="layui-breadcrumb">
                        <a href="">首页/银币卡</a>
                        </span>
                </div>
                <div class="layui-inline" style="right: 0px;position: absolute;">
                    <a class="layui-btn layui-btn-small" style="line-height:20px;margin-top:-6px;float:right" href="javascript:location.replace(location.href);" title="刷新">
                        &nbsp;<i class="layui-icon layui-icon-refresh-3" style="line-height:18px;left: 12px;top:12px;"></i>&nbsp;
                    </a>
                </div>
            </div>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline" style="margin-right: 0px;">
                    <label class="layui-form-label">游戏ID</label>
                    <div class="layui-input-inline">
                        <input type="text" name="gameid" placeholder="游戏ID"  class="layui-input" style="width:200px;">
                    </div>
                </div>
                <div class="layui-inline" style="margin-right: 0px;">
                    <div class="layui-input-inline">
                        <select name="status">
                               <option value='3'  selected>全部用户</option>
                               <option value='1' >在线代理/渠道/推广</option>
                               <option value='2' >在线玩家</option>
                               <option value='0' >离线</option>
                               <option value='4' >冻结玩家</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-right: 0px;">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit="" lay-filter="LAY-user-back-search">
                        搜索
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table class="layui-table" id="admin_table" lay-filter="admin_table"></table>
            <script type="text/html" id="table-sumgold">
                {{ d.gold50*50+d.gold100*100+d.gold200*200}}
            </script>
            <script type="text/html" id="table-useradmin-admin">
                <a class="layui-btn  layui-btn-sm layui-btn-danger"  lay-event="recharge"><i class="layui-icon layui-icon-add-1"></i></a>&nbsp;
                <a class="layui-btn  layui-btn-sm layui-btn-normal"  lay-event="info">&nbsp;―&nbsp;</a>
            </script>
        </div>
    </div>
</div>

<script src="__PUBLIC__/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '__PUBLIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;


        $(".layuiadmin-btn-admin").on("click",function(){
            var gameid = $("input[name=gameid]").val();
            var status = $("select[name=status]").val();
            table.reload('admin_table',{
                page:{
                    curr:1
                }
                ,where:{gameid:gameid,status:status}
            });
        });

        //监听行工具事件
        table.on('tool(admin_table)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'recharge'){
               var id = data.gameid;
               var gold50 = data.gold50;
               var gold100 = data.gold100;
               var gold200 = data.gold200;
                layer.msg('正在加载，请稍后。。', {icon: 16,shade:0.5,time:500,end:function () {
                        layer.open({
                            type: 2,
                            title:'增加银币',
                            skin: 'layui-layer-rim', //加上边框
                            area: ['30%', '50%'], //宽高
                            anim:4,
                            content:"add?id="+id+"&gold50="+gold50+"&gold100="+gold100+"&gold200="+gold200,
                            btn:["确认","取消"],
                            yes:function(e,t){
                                var iform = window['layui-layer-iframe'+e],
                                    submit = t.find('iframe').contents().find('#LAY-user-front-submit');
                                iform.layui.form.on('submit(LAY-user-front-submit)',function (data) {
                                    var field = data.field;
                                    $.ajax({
                                        type:'post',
                                        dataType:"json",
                                        url:'add',
                                        data:field,
                                        success:function (data) {
                                            if(data['code'] == 1){
                                                layer.msg(data['msg'], {icon: 1,end:function () {
                                                        layui.table.reload("admin_table");
                                                    }});
                                            }else{
                                                layer.msg(data['msg'], {icon: 2,end:function () {
                                                        layui.table.reload("admin_table");
                                                    }});
                                            }

                                        },
                                        error:function () {
                                            layer.msg('发生错误', {icon: 2});
                                        },
                                    });
                                    layer.close(e)
                                });
                                submit.trigger('click')

                            },
                        });
                    }});
            } else if(obj.event === 'info'){
                id = data.gameid;
                var gold50 = data.gold50;
                var gold100 = data.gold100;
                var gold200 = data.gold200;
                layer.msg('正在加载，请稍后。。', {icon: 16,shade:0.5,time:500,end:function () {
                        layer.open({
                            type: 2,
                            title:'减去银币',
                            skin: 'layui-layer-rim', //加上边框
                            area: ['30%', '50%'], //宽高
                            anim:4,
                            content:"deleteyinbi?id="+id+"&gold50="+gold50+"&gold100="+gold100+"&gold200="+gold200,
                            btn:["确认","取消"],
                            yes:function(e,t){
                                var iform = window['layui-layer-iframe'+e],
                                    submit = t.find('iframe').contents().find('#LAY-user-front-submit');
                                iform.layui.form.on('submit(LAY-user-front-submit)',function (data) {
                                    var field = data.field;
                                    $.ajax({
                                        type:'post',
                                        dataType:"json",
                                        url:'deleteyinbi',
                                        data:field,
                                        success:function (data) {
                                            if(data['code'] == 1){
                                                layer.msg(data['msg'], {icon: 1,end:function () {
                                                        layui.table.reload("admin_table");
                                                    }});
                                            }else{
                                                layer.msg(data['msg'], {icon: 2,end:function () {
                                                        layui.table.reload("admin_table");
                                                    }});
                                            }

                                        },
                                        error:function () {
                                            layer.msg('发生错误', {icon: 2});
                                        },
                                    });
                                    layer.close(e)
                                });
                                submit.trigger('click')

                            },
                        });
                    }});
            }
        });
        //执行一个 table 实例
        table.render({
            elem: '#admin_table'
            ,url: 'get_gamecard' //数据接口
            ,title: '银币卡'
            ,loading:true
            ,limit:90
            ,page: true //开启分页
            ,cols: [[ //表头
                 {field: 'gameid', align:'center', title: '游戏ID', width:120}
                ,{field: 'nickname', title: '游戏昵称', width:160}
                ,{field: 'gold50', title: '50银币卡', width:160}
                ,{field: 'gold100', title: '100银币卡', width:140}
                ,{field: 'gold200', title: '200银币卡'}
                ,{field: 'usegold', title: '本周已使用银币'}
                ,{field: 'sumgold', title: '剩余银币总额',toolbar: '#table-sumgold'}
                ,{field: 'right', align:'center', maxWidth:220,toolbar: '#table-useradmin-admin'}
            ]],done:function (res) {
               /* for (var i=0;i<res['data'].length;i++){
                    res['data'][i]['sumgold'] = (res['data'][i]['gold50']*50)+(res['data'][i]['gold100']*100)+( res['data'][i]['gold200']*200);
                }*/
            }

        });
    });
</script>
</body>
</html>